package com.ruoyi.web.controller.Tour;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TourSight;
import com.ruoyi.system.service.ITourSightService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 景点管理Controller
 *
 * @author once
 * @date 2020-10-02
 */
@RestController
@RequestMapping("/Tour/sight")
public class TourSightController extends BaseController
{
    @Autowired
    private ITourSightService tourSightService;

    /**
     * 查询景点管理列表
     */
    @PreAuthorize("@ss.hasPermi('Tour:sight:list')")
    @GetMapping("/list")
    public TableDataInfo list(TourSight tourSight)
    {
        startPage();
        List<TourSight> list = tourSightService.selectTourSightList(tourSight);
        return getDataTable(list);
    }

    /**
     * 导出景点管理列表
     */
    @PreAuthorize("@ss.hasPermi('Tour:sight:export')")
    @Log(title = "景点管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TourSight tourSight)
    {
        List<TourSight> list = tourSightService.selectTourSightList(tourSight);
        ExcelUtil<TourSight> util = new ExcelUtil<TourSight>(TourSight.class);
        return util.exportExcel(list, "sight");
    }

    /**
     * 获取景点管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('Tour:sight:query')")
    @GetMapping(value = "/{sightid}")
    public AjaxResult getInfo(@PathVariable("sightid") Long sightid)
    {
        return AjaxResult.success(tourSightService.selectTourSightById(sightid));
    }

    /**
     * 新增景点管理
     */
    @PreAuthorize("@ss.hasPermi('Tour:sight:add')")
    @Log(title = "景点管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TourSight tourSight)
    {
        return toAjax(tourSightService.insertTourSight(tourSight));
    }

    /**
     * 修改景点管理
     */
    @PreAuthorize("@ss.hasPermi('Tour:sight:edit')")
    @Log(title = "景点管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TourSight tourSight)
    {
        return toAjax(tourSightService.updateTourSight(tourSight));
    }

    /**
     * 删除景点管理
     */
    @PreAuthorize("@ss.hasPermi('Tour:sight:remove')")
    @Log(title = "景点管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sightids}")
    public AjaxResult remove(@PathVariable Long[] sightids)
    {
        return toAjax(tourSightService.deleteTourSightByIds(sightids));
    }
}
